package interview.prototype;/*

 */

import java.io.*;
import java.util.Objects;

/**
 * @ClassName Stuand
 * @Author Final
 * @Project DataStructures
 */
public class Stuand implements Cloneable , Serializable {

    private String name;
    private Integer age;

    public Stuand fir;

    public Stuand getFir() {
        return fir;
    }

    public void setFir(Stuand fir) {
        this.fir = fir;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Stuand(String name, Integer age, Stuand fir) {
        this.name = name;
        this.age = age;
        this.fir = fir;
    }

    public Stuand() {

    }
    //克隆方法

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Stuand stuand=null;
        stuand =(Stuand) super.clone();
        return stuand;
    }

    public Object deepClone(){
        ByteArrayOutputStream bos=null;
        ObjectOutputStream oos=null;
        ByteArrayInputStream bis=null;
        ObjectInputStream ois=null;
        try {

            bos=new ByteArrayOutputStream();
            oos=new ObjectOutputStream(bos);
            oos.writeObject(this);

            bis=new ByteArrayInputStream(bos.toByteArray());
            ois=new ObjectInputStream(bis);
            Stuand o =(Stuand) ois.readObject();
            return o;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
        finally {
            try {
                bos.close();
                oos.close();
                bis.close();
                ois.close();
            }catch (Exception e){

                e.printStackTrace();
            }
        }
    }
}
